package com.tre.jdevtemplateboot.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author JDev
 */
public class BasedDesUtils {

    private static final Logger logger = LoggerFactory.getLogger(BasedDesUtils.class);

    private BasedDesUtils() {
        throw new UnsupportedOperationException();
    }

    public static String encryptBasedDes(String base64String) {
        String base64encodedString = null;
        try {
            base64encodedString = Base64.getEncoder().encodeToString(base64String.getBytes(StandardCharsets.UTF_8));
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
        return base64encodedString;
    }

    public static String decryptBasedDes(String cryptData) {
        byte[] base64decodedBytes = Base64.getDecoder().decode(cryptData);
        String base64decodedString = null;
        try {
            base64decodedString = new String(base64decodedBytes, StandardCharsets.UTF_8);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
        return base64decodedString;
    }
}
